from rest_framework import serializers
from .models import KnowledgeDocument, InterviewSession, InterviewQuestion, InterviewAnswer
from django.contrib.auth.models import User

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'username', 'email']

class KnowledgeDocumentSerializer(serializers.ModelSerializer):
    class Meta:
        model = KnowledgeDocument
        fields = '__all__'
        read_only_fields = ['id', 'created_at', 'updated_at']

class InterviewSessionSerializer(serializers.ModelSerializer):
    user = UserSerializer(read_only=True)
    knowledge_documents = KnowledgeDocumentSerializer(many=True, read_only=True)
    
    class Meta:
        model = InterviewSession
        fields = '__all__'
        read_only_fields = ['id', 'created_at', 'updated_at', 'total_score']

class InterviewQuestionSerializer(serializers.ModelSerializer):
    source_document = KnowledgeDocumentSerializer(read_only=True)
    
    class Meta:
        model = InterviewQuestion
        fields = '__all__'
        read_only_fields = ['id', 'created_at']

class InterviewAnswerSerializer(serializers.ModelSerializer):
    question = InterviewQuestionSerializer(read_only=True)
    
    class Meta:
        model = InterviewAnswer
        fields = '__all__'
        read_only_fields = ['id', 'created_at', 'similarity_score', 'quality_score', 'feedback']

class FileUploadSerializer(serializers.Serializer):
    file = serializers.FileField()
    title = serializers.CharField(max_length=200, required=False)

class AnswerSubmissionSerializer(serializers.Serializer):
    answer_text = serializers.CharField()
    question_id = serializers.UUIDField()

class SessionCreateSerializer(serializers.Serializer):
    session_name = serializers.CharField(max_length=200)
    document_ids = serializers.ListField(
        child=serializers.UUIDField(),
        required=False
    )
